package spec.zyh;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;

@WebServlet(name = "RviewServlet")
public class RviewServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            request.setCharacterEncoding("utf-8");
            response.setCharacterEncoding("utf-8");
//            String t = request.getParameter("username");
//            String c = request.getParameter("password");
//            String urL="jdbc:mysql://Localhost:3306/1613580003?characterEncoding=utf8";
//            String name="root";
//            String password="123456";
//            Class.forName("com.mysql.jdbc.Driver");
//            Connection com= null;
//            com = DriverManager.getConnection(urL,name,password);
//            Statement s=com.createStatement();
            DatabaseConnetion dbc=new DatabaseConnetion();
            Connection com=dbc.getConnection();
            Statement s = null;
            s = com.createStatement();
            String id=request.getParameter("id");
            response.setContentType("text/html");
            String title = request.getParameter("title");
            String content = request.getParameter("content");
            ResultSet rs=s.executeQuery("select * from t_news where id="+id);
            PrintWriter out1 = response.getWriter();
            String h=" ";
            h +="<!DOCTYPE html>\n" +
                    "<html lang=\"en\">\n" +
                    "<head>\n" +
                    "    <meta charset=\"UTF-8\">\n" +
                    "    <title>修改</title>\n" +
                    "</head>\n" +
                    "<body>\n" +
                    "<script>\n" +
                    "    alert(\"需要登录用户才能更改\");\n" +
                    "</script>\n" +
                    "<form action=\"ModificationServlet\" method=\"post\">\n" +
                    "    <input type=\"button\" value=\"返回上一页\" id=\"f\" style=\"color:gray; font-size: 18px;\"><br><br>\n" ;
                  while (rs.next()) {
                   h += "  标题：  <input type=\"text\"   style=\"width: 500px ;height: 20px\" value='" + rs.getString("title") + "' palceholder=\"请修改标题\" name=\"title\" ><br><br>\n" +
                        " 内容：  <input type=\"text\"   style=\"width: 500px ;height: 20px\" value='" + rs.getString("content") + "' palceholder=\"请修改内容\" name=\"content\"><br><br>\n"+
                          "<input type=\"text\" value='" + id + "' style='display:none' name=\"id\" ><br><br>\n";
                  }
                    h +="    <input type=\"submit\" value=\"保存\" id=\"b\" style=\"color:gray; font-size: 24px;margin-left: 80px;margin-right: 80px\">\n" +
                    "</form>\n" +
                    "<script>\n" +
                    "    var f= document.getElementById(\"f\");\n" +
                    "    f.onclick=function () {\n" +
                    "        window.open('login.html');\n" +
                    "    }\n" +
                    "</script>\n" +
                    "</body>\n" +
                    "</html>";
            out1.println(h);
            dbc.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    }

